home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / AnchorHelper.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  1.1 KB  |  67 lines

  1. //  Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. function CheckNewAnchor( name )
  4. {
  5.     var errStr = CheckName( name );
  6.     if ( errStr.length > 0 )
  7.         return errStr;
  8.  
  9.     var count = _countAnchorsNamed( name ); 
  10.     if ( count > 0 )
  11.     {
  12.         return MM.MSG_DuplicateName;
  13.     }
  14.  
  15.     return "";
  16. }
  17.  
  18. function CheckEditAnchor( old_name, name )
  19. {
  20.     if ( name == old_name )
  21.         return "";
  22.  
  23.     var errStr = CheckName( name );
  24.     if ( errStr.length > 0 )
  25.         return errStr;
  26.  
  27.     var count = _countAnchorsNamed( name ); 
  28.     if ( count > 0 )
  29.         return MM.MSG_DuplicateName;
  30.  
  31.     return "";
  32. }
  33.  
  34. var _count = 0;
  35.  
  36. function _findAnchorNamed( tag, name )
  37. {
  38.     if ( tag.tagName == "A" && tag.getAttribute( "name" ) == name )
  39.         _count++;
  40.     return true;
  41. }
  42.  
  43. function _countAnchorsNamed( name )
  44. {
  45.    _count = 0;
  46.    var root = dw.getDocumentDOM().documentElement;
  47.    traverse(root, _findAnchorNamed, null, null, name );
  48.    return _count;
  49. }
  50.  
  51. function CheckName( name )
  52. {
  53.     if ( name.search( /\W/ ) != -1 )
  54.     {
  55.         return MM.MSG_InvalidName;
  56.     }
  57.  
  58.     name.replace( /\W/, "" );
  59.  
  60.     if ( name.length < 1 )
  61.     {
  62.         return MM.MSG_EmptyName;
  63.     }
  64.  
  65.     return "";
  66. }
  67.